home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / visual / perl.exe / {app} / Plug-Ins / SubroutineNavigator.pl < prev    next >
Encoding:
Text File  |  2003-04-15  |  1.8 KB  |  76 lines

  1. #Name: Subroutine Navigator
  2. #Description: Perl script to navigate through subroutines in file using Ctrl+Shift+Up & Down arrows (\optiperl\plug-ins\SubroutineNavigator.pl)
  3. #Icon: %opti%Tools.icl,148
  4. ##Extensions: Startup
  5.  
  6. #Remove second # above to load at startup
  7.  
  8.  
  9. use Win32::OLE;
  10.  
  11. sub Initialization {
  12.  $optiperl = Win32::OLE->new('OptiPerl.Application');
  13.  if (defined $valid_plugin) {
  14.   $plug_id = $_[0];
  15.   my $menu = $optiperl->CreateToolItem($plug_id,"menu");
  16.   $menu->SetOptions("Menu","","","","");
  17.  
  18.   my $btn = $optiperl->CreateToolItem($plug_id,"button");
  19.   $btn->SetOptions(
  20.       "Find next","Find next subroutine",
  21.       "%opti%tools.icl,157","Ctrl+Shift+Down","do_findnext");
  22.   $menu->ToolLinks->Add($btn,0);
  23.  
  24.   $btn = $optiperl->CreateToolItem($plug_id,"button");
  25.   $btn->SetOptions(
  26.       "Find previous","Find previous subroutine",
  27.       "%opti%tools.icl,158","Ctrl+Shift+Up","do_findprev");
  28.   $menu->ToolLinks->Add($btn,0);
  29.  
  30.   $optiperl->ToolBarLinks($plug_id)->AssignLinks($menu->ToolLinks);
  31.   $optiperl->UpdateToolBars($plug_id);
  32.   $optiperl->ToolBarVisible($plug_id,1);
  33.  }
  34. }
  35.  
  36. sub Finalization {
  37. }
  38.  
  39. sub _find_next {
  40.  my $doc = $optiperl->ActiveDocument;
  41.  my $i = $optiperl->ActiveDocument->CursorPosY+$_[0];
  42.  my $totallines = $doc->LineCount;
  43.  while (($i<$totallines) and ($i>=0) and
  44.         ($doc->lines($i) !~/^\s*sub (\w+)/)) {
  45.   $i=$i+$_[0];
  46.  }
  47.  if (($i < $totallines) and ($i>=0)) {
  48.   $doc->TempHightlightLine($i);
  49.  
  50.   return 1;
  51.  }
  52.  else {
  53.   return 0;
  54.  }
  55. }
  56.  
  57.  
  58. sub do_findnext {
  59.  if (!_find_next(1)) {
  60.    $optiperl->ActiveDocument->{CursorPosY} = 0;
  61.    _find_next(1);
  62.   }
  63. }
  64.  
  65. sub do_findprev {
  66.  if (!_find_next(-1)) {
  67.    $optiperl->ActiveDocument->{CursorPosY}=
  68.        $optiperl->ActiveDocument->LineCount-1;
  69.    _find_next(-1);
  70.   }
  71. }
  72.  
  73. if (! defined $valid_plugin)
  74. {
  75.  Initialization;
  76. }